<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Prototype JSON</title>
<script type="text/javascript">
	var People = {
			create: function(name, age) {
				this.name = name;
				this.age = age;
			},
			sayHello: function() {
				alert("Hello, my name is " + this.name + ".I'm " + this.age);				
			}
	};
	
	/*var X = function() {};
	X.prototype = People;
	
	var p = new X();
	p.create("Somebody", 21);
	p.sayHello();*/
	
	var Factory = {
		createObject: function(className, arg0, arg1) {
			var temp = function() {
				className.create(arg0, arg1);
			};
			temp.prototype = className;
			
			var result = new temp();
			result.create(arg0, arg1);
			return result;
		}
	};
	
	var people = Factory.createObject(People, "Somebody", 21);
	people.sayHello();
</script>
<!-- <script type="text/javascript">
	var Automobile = {
		create: function(brand, serial) {
			this.brand = brand;
			this.serial = serial;
		},
		introduce: function() {
			alert("This is " + this.brand + " car,serial is " + this.serial);
		}
	};

	var car = Factory.createObject(Automobile, "Someone", "New");
	car.introduce();
</script> -->
<script type="text/javascript">
	var Factory = {
			create: function(className, params) {
				var temp = function() {
					//className.create.apply(this, params);
				};
				temp.prototype = className;
				
				var result = new temp();
				className.create.apply(result, params);
				return result;
			}
	};
	var people = Factory.create(People, ["Somebody", 21]);
	people.sayHello();
</script>
</head>
<body>

</body>
</html>